using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Globals;
using Presentation.Contracts;
using Presentation;
using DataAccess;

namespace ProjektZespolowy.Profile
{
    public partial class ShowProfile : System.Web.UI.Page,IShowProfileView
    {
        private ShowProfilePresenter presenter;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            presenter = new ShowProfilePresenter(this);
        }

        protected void Page_Load(object sender, EventArgs e)
        {

                
            presenter.fillUserData();
            presenter.fillUserForums();
            presenter.fillUserComments();
            presenter.fillUserFriends();
            presenter.fillBestRated();
            presenter.fillLastAdded();
            presenter.fillGalleries();


            //refresh user photo
            avatar.ImageUrl = presenter.hasAvatar() ?
                "/GetUserPicture.aspx?id=" + UserId :
                "/images/blank-photo.gif";

            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]) && !
                    string.IsNullOrEmpty(Session[ContentNamesGlobals.SessionWithUserId].ToString())
                    && Session[ContentNamesGlobals.SessionWithUserId].ToString() != Request.QueryString["id"])
                {
                    upUser.Visible = true;
                    btnSendMessage.PostBackUrl = "/Mail/CvMessage.aspx?UserID=" + UserId;
                }
            }
        }

        /// <summary>
        /// Gets the user id.
        /// </summary>
        /// <value>The user id.</value>
        public int UserId
        {

            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    return int.Parse(Request.QueryString["id"]);
                }
                else
                {
                    return int.Parse(Session[ContentNamesGlobals.SessionWithUserId].ToString());
                }
            }
        }

        /// <summary>
        /// Gets or sets the name of the first.
        /// </summary>
        /// <value>The name of the first.</value>
        public string FirstName
        {
            get
            {
                return imieLabel.Text;
            }
            set
            {
                imieLabel.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the name of the last.
        /// </summary>
        /// <value>The name of the last.</value>
        public string LastName
        {
            get
            {
                return nazwiskoLabel.Text;
            }
            set
            {
                nazwiskoLabel.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the email.
        /// </summary>
        /// <value>The email.</value>
        public string Email
        {
            get
            {
                return emailLabel.Text;
            }
            set
            {
                emailLabel.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the gg.
        /// </summary>
        /// <value>The gg.</value>
        public string Gg
        {
            get
            {
                return ggLabel.Text;
            }
            set
            {
                ggLabel.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the skype.
        /// </summary>
        /// <value>The skype.</value>
        public string Skype
        {
            get
            {
                return skypeLabel.Text;
            }
            set
            {
                skypeLabel.Text = value;
            }
        }

        /// <summary>
        /// Gets or sets the login.
        /// </summary>
        /// <value>The login.</value>
        public string Login
        {
            get
            {
                return loginLabel.Text;
            }
            set
            {
                loginLabel.Text = value;
            }
        }

        public List<forum> Forums
        {
            get
            {
                return (List<forum>)forumsReperater.DataSource;
            }

            set
            {
                forumsReperater.DataSource = value;
                forumsReperater.DataBind();
            }
        }

        public IList<comment> Comments
        {

            set
            {
                commentsRepeater.DataSource = value;
                commentsRepeater.DataBind();
            }

        }

        public IList<user> Friends
        {
            set
            {
                friendsRepeater.DataSource = value;
                friendsRepeater.DataBind();
            }
        }

        public IList BestRated
        {
            set 
            {
                bestRatedRepeater.DataSource = value;
                bestRatedRepeater.DataBind();
            }
        }

        public IList<art> LastAdded
        {
            set
            {
                lastAddedRepeater.DataSource = value;
                lastAddedRepeater.DataBind();
            }
        }

        public IList<gallery> Galleries
        {
            set
            {
                galleryRepeater.DataSource = value;
                galleryRepeater.DataBind();
            }
        }

        protected void btnAddFriend_Click(object sender, ImageClickEventArgs e)
        {
            presenter.sendInvitation(int.Parse(Session[ContentNamesGlobals.SessionWithUserId].ToString()));
            actionPanel.Visible = true;
        }

        public string GetAvatar(user u)
        {

            return u.avatar_mime == null ? "/images/blank-photo.gif" : "/GetUserPicture.aspx?id=" + u.id.ToString();

        }

        public string GetMiniFoto(string bigFoto)
        {
            if (string.IsNullOrEmpty(bigFoto))
                return "";
            string extension = System.IO.Path.GetExtension(bigFoto);
            bigFoto = bigFoto.Replace(extension, string.Empty);
            return bigFoto + "_mini" + extension;
        }

    }
}
